package com.ysd.lis.service.eq.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.eq.EqPollingProject;
import com.ysd.lis.entity.eq.EqPollingStandard;
import com.ysd.lis.mapper.eq.EqPollingProjectMapper;
import com.ysd.lis.request.CommonPageDto;
import com.ysd.lis.request.eq.PollingProjectDto;
import com.ysd.lis.service.eq.EqPollingProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 设备管理-设备类型 服务实现类
 * </p>
 *
 * @author prs
 * @since 2024-07-31
 */
@Service
public class EqPollingProjectServiceImpl extends ServiceImpl<EqPollingProjectMapper, EqPollingProject> implements EqPollingProjectService {

    @Autowired
    EqPollingProjectMapper eqPollingProjectMapper;
    @Override
    public Result findPollingProjectList(CommonPageDto param) {
        MPJLambdaWrapper<EqPollingProject> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(EqPollingProject.class);
        if (StringUtils.isNotBlank(param.getPid())) {
            queryWrapper.eq(EqPollingProject::getStandardId,param.getPid());
        }

        queryWrapper.eq(EqPollingProject::getDelFlag, 0)
                .orderByAsc(EqPollingProject::getSeq);
        return Result.succ(1, "查询成功", eqPollingProjectMapper.selectList(queryWrapper));
    }

    @Override
    public Result addPollingProject(EqPollingProject project) {
        int insert = eqPollingProjectMapper.insert(project);
        if(insert>0){
            return Result.succ(1, "添加成功", project);
        }else {
            return Result.succ(400, "添加失败", "");
        }
    }

    @Override
    public Result editPollingProject(EqPollingProject project) {
        int updateById = eqPollingProjectMapper.updateById(project);
        if(updateById>0){
            return Result.succ(1, "修改成功", project);
        }else {
            return Result.succ(400, "修改失败", "");
        }
    }

    @Override
    public Result batchDeletePollingProjectList(PollingProjectDto dto) {
        List<EqPollingProject> pollingProjectList = dto.getPollingProjectList();
        List<String> ids = pollingProjectList.stream().map(EqPollingProject::getId).collect(Collectors.toList());


        boolean b = this.removeByIds(ids);
        if(b){
            return Result.succ(1, "删除成功", null);
        }else {
            return Result.fail(400,"删除失败","");
        }
    }
}
